﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using BrnMall.Core;
using BrnMall.Services;
using BrnMall.Web.Framework;
using BrnMall.Web.MallAdmin.models;

namespace BrnMall.Web.MallAdmin.controllers
{
	public partial class DistributionController: BaseMallAdminController
	{
		[HttpGet]
		public ActionResult DistributionParam()
		{
			var info = Services.AdminDistributionService.GetDistributionParam();
			info = info ?? new DistributionParamInfo {LevelPercent = new List<Tuple<int, double>>()};
			var model = new DistributionParamModel
			{
				Id = info.DistributionId,
				TotalLevel = info.TotalLevel,
				LevelPercent = info.LevelPercent,
				ProductPumpedType = info.ProductPumpedType,
				ProductPumpedValue = info.ProductPumpedValue
			};
			return View(model);
		}
		[HttpPost]
		public ActionResult DistributionParam(DistributionParamModel model)
		{
			var info = new DistributionParamInfo
			{
				DistributionId = model.Id,
				TotalLevel = model.TotalLevel,
				LevelPercent = model.LevelPercent,
				ProductPumpedType = model.ProductPumpedType,
				ProductPumpedValue = model.ProductPumpedValue
			};
			AdminDistributionService.SaveDistributionParam(info);

			return RedirectToAction("DistributionParam");
		}
	}
}
